package com.cntv.lifecycledemo.java;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.cntv.lifecycledemo.R;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView tv = findViewById(R.id.textView);
        tv.setText("自动暂停和启动的计时器");
        findViewById(R.id.button).setVisibility(View.INVISIBLE);
        Button btn2 = findViewById(R.id.button2);

        btn2.setText("进入下一页");
        btn2.setOnClickListener(v -> {
            startActivity(new Intent(this, com.cntv.lifecycledemo.kotlin.MainActivity.class));
        });

//  AutoLifeCycleChronometer实现了LifecycleObserver接口 观察生命周期
        AutoLifeCycleChronometer chronometer = findViewById(R.id.chronometer);
        getLifecycle().addObserver(chronometer);//只需添加需要感知生命周期的观察者即可

    }
}